#include<stdio.h>
int main()
{
    //freopen("in.txt","r",stdin);
    int n,x;
    while (scanf("%d %d",&n,&x) != EOF && !(n == 0 && x == 0))
    {
        int count = 0;
        for(int i = 1; i <= n; i++)
        {
            for(int j = i+1; j <= n; j++)
            {
                for(int k = j +1; k <= n; k++)
                {
                    if(i + j + k == x) count++;
                }
            }
        }
        printf("%d\n",count);
    }
    
}